<template>
	<view>
		<view>
			<view class="headBox"
				:style="{'background-image':`url(https://boyubasketball.oss-cn-shanghai.aliyuncs.com/${bgHB}.png)`}">
				<!-- 	<view class="head_nav" :style="'height:' + navHeight + 'px;background:rgba(255,40,64,' + scrollTop + ')'">
					<view class="head_title" :style="'top:' + navTop + 'px'">个人中心</view>
				</view> -->
				<!-- #ifdef MP-TOUTIAO -->
				<view class="bgcBox" style="top: 32rpx;">
				<!-- #endif -->
					<!-- #ifdef H5||APP-PLUS -->
					<view class="bgcBox" :style="'top:' + navHeight + 'px'">
					<!-- #endif -->
						<!-- 未登录的状态 -->
						<view class="head">
							<view class="head-detail" v-if="!isLogin" @click="goLogin">
								<image src="/static/image/mine/head.png" class="headImg"></image>
								<text class="head-text">登录/注册</text>
							</view>
							<view class="head-detail" v-if="isLogin">
								<!-- <image src="/static/image/mine/head.png" class="headImg"></image>
								<text class="head-text">微信昵称</text> -->
								<image :src="userInfoData&&userInfoData.sysUser&&userInfoData.sysUser.avatar"
									class="headImg"></image>
								<text
									class="head-text">{{userInfoData&&userInfoData.sysUser&&userInfoData.sysUser.nickName}}</text>
							</view>
						</view>
					</view>
				</view>
				<view class="contentBox p3">
					<view class="bf bs16 p3" style="box-shadow: 0px -3px 6px rgba(104, 104, 104, 0.18);">
						<view class="pb30 b-b f30">球队({{teamList.length}})</view>
						<view class="c9 f26 t-c p30" v-if="teamList.length==0">暂无数据</view>
						<view class="" v-else>
							<view @click="editInfo(item)" v-for="(item,index) in teamList" :key="index"
								class="b-b p20 f-s-c">
								<view class="f-y-c">
									<image :src="item.logo" class="bshalf" style="width: 70rpx;height: 70rpx;"></image>
									<view class="ml20">
										<view class="f26">{{item.name || '球队名称'}}</view>
										<view class="f-y-c mt10">
											<view style="padding: 5rpx;font-size: 18rpx;background: #F4F4F4;">
												{{item.phone}}
											</view>
											<view class="ml15 cf bs10"
												style="font-size: 18rpx;padding: 5rpx;background: #099D4D;">
												{{item.province}}
											</view>
										</view>
									</view>
								</view>
								<u-icon name="arrow-right" size="16" color="#333"></u-icon>
							</view>
						</view>
					</view>
				</view>
				<view>
					<tabbar ref="tabbar" type="1" @tabEvent="getNoticeInfo"></tabbar>
				</view>
			</view>

			<!-- 自定报价查看提醒框 -->
			<!-- <u-modal :show="isInfo" title="提示" confirmText="前往开通" showCancelButton @confirm="handlerInfoConfirm"
				@cancel="isInfo=!isInfo">
				<view class="f34 t-c" style="position: absolute;right: 50rpx;top: 50rpx;">
					<u-icon size="32rpx" color="#000" name="close" @tap="isInfo=!isInfo" />
				</view>
				<view class="p3 f28">
					<view class="mb20 t-c">该功能需要开通报价会员使用</view>
					<view class="c6">{{ memberInfoStr }}</view>
				</view>
			</u-modal>

			<login ref="login" :hasLogin="isLogin" @onLoginSuccess="loginSuccess($event, { tagId: 'login' })"></login> -->
		</view>
</template>

<script>
	import tabbar from '../../tabbarComponent/tabbar';
	import login from '@/components/login-view/login-view';
	const app = getApp();

	const $URL = require('../../request/request');

	const $token = require('../../utils/token.js');

	const $flow = require('../../utils/flow.js');

	const $user = require('../../request/api/v1/user.js');

	const $index = require('../../request/api/v1/index');
	const $member = require("../../request/api/v1/member.js");
	const $quotation = require('../../request/api/v1/quotationChange')
	var call = require('../../components/call');
	export default {
		components: {
			tabbar,
			login
		},
		data() {
			return {

				isLogin: false,
				teamList: [],
				userInfo: {
					face: '/static/image/mine/head.png',
					username: '',
					score: '',
					rankName: '',
					is_show: false,
					mobile: '',
					uid: '',
					commonly_used_functions: [],
					member_package: {},
				},

				num: {
					dqr: 0,
					ycj: 0,
					yxd: 0,
					zjz: 0,
					shipped: ''
				},

				navHeight: app.globalData.navHeight,
				navTop: app.globalData.navTop,
				scrollTop: 0,

				integral: {
					integral_dsh: 0,
					integral_sh: 0,
					integral_ysh: 0,
					integral_ywc: 0
				},

				withdraw_is_need_auth: '',
				user_auth_type: '',
				take_photos_cost_status: 0,
				activity_img: '',
				image_is_order: '',
				integral_draw_status: '',
				join: '',
				notice_num: 0,
				is_show: '',
				my_center_banner: '',
				isInfo: false,
				memberInfoStr: '',
				//
				userInfoData: {},
				bgHB: ''
			};
		},
		onLoad: function(options) {
			this.bgHB = $URL.getBaseUrl() == 'http://bm.yundongshugen.com/api' ? '1751981522313weilaixing' :
				'1756008365913logo'
			uni.hideTabBar({
				animation: false
			});
			this.$nextTick(() => {
				this.$refs.tabbar.editTabbar(this.notice_num);
			});
			// let menuButtonObject = uni.getMenuButtonBoundingClientRect();
			// var that = this;
			// uni.getSystemInfo({
			// 	success: function(res) {
			// 		let statusBarHeight = res.statusBarHeight;
			// 		let navTop = menuButtonObject.top;
			// 		let //胶囊按钮与顶部的距离
			// 			navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2; //导航高度
			// 		this.navHeight=navHeight;
			// 		this.navTop=navTop;

			// 	}
			// });
		},
		onShow: function() {

			let isLogin = localStorage.getItem("tokenValue") ? true : false
			console.log('isLoginisLogin', isLogin)
			if (isLogin) {
				// this.getNoticeInfo(); //无需每次调用，已经在 tabbar导航栏 每次都调用了
			}

			this.isLogin = isLogin;
			// this.getUserInfo();
			let that = this;
			this.userInfoData = JSON.parse(localStorage.getItem('userInfo')) || ''
			this.getTeamList()
		},
		onPageScroll(e) {
			let scrollTop = 0;

			if (e.scrollTop <= 100) {
				scrollTop = e.scrollTop / 100;
			} else {
				scrollTop = 1;
			}

			this.scrollTop = scrollTop;
		},
		methods: {
			editInfo(item) {
				localStorage.setItem('teamObj', JSON.stringify(item))
				setTimeout(() => {
					uni.navigateTo({
						url: `/pages/business/matchDetail?contestId=${item.contestId}&teamId=${item.id}`
					});
				}, 1000)
				// uni.navigateTo({
				// 	url: '/pages/business/joinMatch?sourceType=matchDetail'
				// });
			},
			getTeamList() {
				$index.myTeam({
					indexId: $URL.getBaseUrl() == 'http://bm.yundongshugen.com/api' ? 1 : 2
				}).then(res => {
					this.teamList = res.data
				})
			},
			goLogin() {
				localStorage.clear();
				uni.navigateTo({
					url: '/pages/business/wxLogin'
				});
			},
			getPhoneNumber(e) {
				this.$refs.login.getPhoneNumber(e);
			},

			getPhoneNumbers(e) {
				this.$refs.login.getPhoneNumber(e);
			},

			loginSuccess(e, _dataset) {
				/* ---处理dataset begin--- */
				//this.datasetHandle(e, _dataset);
				/* ---处理dataset end--- */
				uni.navigateTo({
					url: e.detail.payload.link
				});
			},

			loginSuccesss(e, _dataset) {
				/* ---处理dataset begin--- */
				//this.datasetHandle(e, _dataset);
				/* ---处理dataset end--- */
				if ($flow.getFlow() == 0) {
					uni.navigateTo({
						url: e.detail.payload.link
					});
				} else {
					uni.navigateTo({
						url: '/pages/mine/flowForm/flowForm'
					});
				}

				return;

				if (e.detail.payload.image_is_order == 0) {
					uni.navigateTo({
						url: '/pages/openPackage/openPackage'
					});
				} else {
					uni.navigateTo({
						url: '/pages/identify/identify'
					});
				}
			},

			getUserInfo() {
				console.log('uni.getSystemInfoSync()', uni.getSystemInfoSync())
				$user
					.getUserInfo()
					.then(res => {
						this.userInfo.face = res.face;
						this.userInfo.username = res.nickname;
						this.userInfo.score = res.score;
						this.userInfo.uid = res.uid;
						this.userInfo.mobile = res.mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
						this.userInfo.rankName = res.levelinfo.now_info.name;
						this.userInfo.commonly_used_functions = res.commonly_used_functions;
						this.userInfo.member_package = res.member_package
						this.userInfo.user_offer_msg = res.user_offer_msg
						$flow.setFlow(res.apply_info);
						this.userInfo = this.userInfo;
						this.num = res.num;
						this.activity_img = res.my_center_banner;
						this.integral = res.integral;
						this.image_is_order = res.image_is_order;
						this.withdraw_is_need_auth = res.withdraw_is_need_auth;
						this.user_auth_type = res.user_auth_type;
						this.integral_draw_status = res.integral_draw_status;
						this.join = res.is_store;
						this.userInfo.iosShow = res.iosShow
						if (res.is_login == 1) {
							this.isLoginFun();
						} else {
							this.isLogin = false;
						}

						if (res.lng !== 0) {
							$token.setIsLocation(true);
						}
					})
					.catch(() => {
						this.isLogin = false;
					});
			},

			getNoticeInfo(e) {
				let res = e //.detail
				// $index.noticeInfo().then(res => {
				if (res.feedback_num > 0) {
					app.globalData.is_show = true;
				} else {
					app.globalData.is_show = false;
				}

				this.notice_num = res.notice_num;
				this.is_show = app.globalData.is_show;
				this.$refs.tabbar.editTabbar(this.notice_num);
				// });
			},

			isLoginFun() {
				this.isLogin = true;
			},
			toMember() {
				if (this.isLogin == false || !this.userInfo.iosShow) {
					return false;
				}
				uni.navigateTo({
					url: '/pagesA/memberSystem/member/member',
				})
			},
			toOrder() {
				if (this.isLogin == false) {
					return false;
				}

				app.globalData.userOrderType = 0;
				uni.navigateTo({
					url: '/pages/orderlist/orderlist'
				});
			},

			oneOrder() {
				if (this.isLogin == false) {
					return false;
				}

				app.globalData.userOrderType = 1;
				uni.navigateTo({
					url: '/pages/orderlist/orderlist'
				});
			},

			twoOrder() {
				if (this.isLogin == false) {
					return false;
				}

				app.globalData.userOrderType = 2;
				uni.navigateTo({
					url: '/pages/orderlist/orderlist'
				});
			},

			thereOrder() {
				if (this.isLogin == false) {
					return false;
				}

				app.globalData.userOrderType = 3;
				uni.navigateTo({
					url: '/pages/orderlist/orderlist'
				});
			},

			fourOrder() {
				if (this.isLogin == false) {
					return false;
				}

				app.globalData.userOrderType = -1;
				uni.navigateTo({
					url: '/pages/orderlist/orderlist'
				});
			},

			tomywallet() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/mywallet/mywallet?withdraw_is_need_auth=' + this.withdraw_is_need_auth +
						'&user_auth_type=' + this.user_auth_type
				});
			},

			tomyIntegral(e) {
				if (this.isLogin == false) {
					return false;
				}

				const {
					integral_draw_status
				} = e.currentTarget.dataset;
				uni.navigateTo({
					url: '/pages/myIntegral/myIntegral?integral_draw_status=' + integral_draw_status
				});
			},

			tomyIntegralMall() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/myIntegral/IntegralMall/IntegralMall'
				});
			},

			toinvite() {
				// if (this.isLogin == false) {
				// 	return false;
				// }
				uni.navigateTo({
					url: '/pages/invite/invite'
				});
			},

			toFlow() {
				uni.navigateTo({
					url: '/pages/flow/flow'
				});
			},

			toUpdateData() {
				uni.navigateTo({
					url: '/pages/mine/updateData/updateData'
				});
			},

			toSetting() {
				uni.navigateTo({
					url: '/pages/mine/settingConfig/settingConfig'
				});
			},

			toCommission() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/commission/commission'
				});
			},

			toNotice() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/mine/notice/notice'
				});
			},

			toFkjg() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/mine/fkjg/fkjg'
				});
			},

			//预约快递
			appointmentExpress() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/mine/appointmentExpress/appointmentExpress'
				});
			},

			toCoupon() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/allCoupon/allCoupon'
				});
			},

			tocall() {
				return call.call('18856885222');
			},

			toPartner() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/partner/partner'
				});
			},

			addWx() {
				uni.previewImage({
					urls: [
						'https://smhs-1258084849.cos.ap-nanjing.myqcloud.com/smhswbulk/2023-09-13/22bea202309131820153486.image/png'
					]
				});
			},

			toStore() {
				uni.navigateTo({
					url: '/pages/storeList/storeList'
				});
			},

			// 申请流量主
			toFlowHost() {
				if (this.isLogin == false) {
					return false;
				}

				if ($flow.getFlow() == 1) {
					uni.navigateTo({
						url: '/pages/mine/flowForm/flowForm'
					});
				} else {
					uni.navigateTo({
						url: '/pages/mine/flowHost/flowHost'
					});
				}
			},

			toCost() {
				if (this.isLogin == false) {
					return false;
				}

				// if (this.image_is_order == 0) {
				// 	uni.navigateTo({
				// 		url: '/pages/openPackage/openPackage'
				// 	});
				// } else {
				// 	uni.navigateTo({
				// 		url: '/pages/identify/identify'
				// 	});
				// }
				uni.navigateTo({
					url: '/pages/identifyList/identifyList'
				});
			},

			toAction(e) {
				const {
					my_center_banner
				} = e.detail;
				this.activity_img = my_center_banner;
			},

			toActivity() {
				uni.navigateTo({
					url: '/pages/activity/activity'
				});
			},

			async handlerFlex(e) {
				const {
					item
				} = e.currentTarget.dataset;

				if (item.type == 3) {
					return false;
				}

				if (item.type == 2) {
					uni.navigateToMiniProgram({
						appId: item.content.appid,
						path: item.content.link_url,
						envVersion: 'release',

						success(res) {
							// console.log("打开成功")
						}
					});
				} else if (item.type == 0) {
					if (item.content.link_url == '') {
						return false;
					}

					uni.navigateTo({
						url: '/pages/externalLink/externalLink?item=' + item.content.link_url
					});
				} else if (item.type == 4) {
					//   uni.navigateTo({
					//     url: '/pages/enterForm/enterForm'
					//  });
				} else if (item.type == 1) {
					if (item.content.content == '') {
						return false;
					}

					uni.navigateTo({
						url: '/pages/richText/richText?item=' + encodeURIComponent(JSON.stringify(item.content
							.content))
					});
				} else if (item.type == 5) {
					if (this.isLogin == false) {
						return false;
					}
					uni.navigateTo({
						url: item.content.link_url
					});
				}
			},
			async toQuotationChange() {
				let res = await this.getUserPackages()
				if (res.data.endtime == '-1' || res.data.endtime == '-2') {
					// 非会员
					uni.navigateTo({
						url: '/pagesA/memberSystem/memberPageShow/memberPageShow?text=' + res.text
					})
				} else {
					// 是会员
					$quotation.PriceChangeStatus().then(res => {
						let statusObj = res
						if (res.status == 0) {
							uni.showToast({
								title: '即将上线',
								icon: 'none'
							})
						} else {
							uni.navigateTo({
								url: '/pagesA/quotationChange/quotationChange?statusObj=' + JSON
									.stringify(statusObj)
							})
						}
					})
				}
			},
			// 收藏报价单
			async tocustom() {
				let res = await this.getUserPackages()
				if (res.data.endtime == '-1' || res.data.endtime == '-2') {
					// 非会员
					this.isInfo = true
					this.memberInfoStr = '功能介绍：可关注型号，并把关注的型号集合到一个报价单展示'
				} else {
					// 是会员
					uni.navigateTo({
						url: '/pagesA/customQuotation/customQuotation/customQuotation'
					});
				}
			},
			// 报价短信通知
			async msgNotice() {
				let res = await this.getUserPackages()
				if (res.data.endtime == '-1' || res.data.endtime == '-2') {
					// 非会员
					this.isInfo = true
					this.memberInfoStr = '功能介绍：设置关注的型号或品牌，价格变动将短信通知'
				} else {
					// 是会员
					uni.navigateTo({
						url: '/pagesA/modulePages/quotationMsgNotice/msgNoticeTable/msgNoticeTable'
					});
				}
			},
			handlerInfoConfirm() {
				uni.navigateTo({
					url: '/pagesA/memberSystem/member/member',
				})
			},
			getUserPackages() {
				return new Promise((resolve, reject) => {
					$member.getUserPackages({
						page: 1
					}).then((res) => {
						resolve(res)
					})
				})
			},
			handlerIntegral(e) {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: e.currentTarget.dataset.link
				});
			},

			toIntegralDraw() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/luckyDraw/luckyDraw'
				});
			},

			//vip分享
			toInvitation() {
				if (this.isLogin == false) {
					return false;
				}

				uni.navigateTo({
					url: '/pages/mine/invitation/invitation'
				});
			},

			//上传图片
			uploadimg(e) {
				var that = this;
				let token = uni.getStorageSync('token');
				var tempFilePaths = e.detail.avatarUrl;
				let baseURL = $URL.getBaseUrl();
				//  选择图片
				uni.chooseImage({
					count: 1,
					sizeType: ['original', 'compressed'],
					sourceType: ['album', 'camera'],
					success(res) {
						uni.showToast({
							title: '正在上传...',
							icon: 'loading',
							mask: true,
							duration: 1000
						});

						const COS = require('@/utils/cos-wx-sdk-v5.min.js')
						const cos = new COS({
							SimpleUploadMethod: 'putObject',
							AppId: '1258084849',
							SecretId: 'AKIDtingfUXZqwrfPxLeqrhGQK4c0d199jeK',
							SecretKey: 'cyaw1YoqeBShiSu51jALZhYtW6RVIyRd'
						})
						let nowDate = new Date()
						let date = {
							year: nowDate.getFullYear(),
							month: nowDate.getMonth() + 1,
							date: nowDate.getDate()
						}
						const systemTime = `${date.year}-${date.month}-${date.date}`
						let fileName = res.tempFilePaths[0].substr(res.tempFilePaths[0].lastIndexOf('/') + 1);
						cos.postObject({
								Bucket: 'smhs', // 存储桶
								Region: 'ap-nanjing', // 地域
								Key: 'smhswbjd/upload/' + systemTime + '/' + fileName,
								FilePath: res.tempFilePaths[0],
							},
							function(err, data) {
								that.uploadPreservation('http://' + data.Location);
							})
					}
				});
			},

			uploadPreservation(url) {
				$user
					.editinformation({
						face: url
					})
					.then(res => {
						uni.showToast({
							title: '修改成功',
							icon: 'success'
						});
						this.getUserInfo();
					})
					.catch(() => {
						uni.showToast({
							title: '修改失败',
							icon: 'error'
						});
					});
			}
		}
	};
</script>
<style>
	@import './mine.css';
</style>